home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Frameworks / Argus Frameworks 2.1 / Argus Libraries 2.1 / FnTE.cp < prev   
Text File  |  1996-01-02  |  21KB  |  716 lines

  1. /**********************************************************************
  2.  
  3.     FnTE.cp
  4.  
  5. ***********************************************************************/
  6.  
  7. /*
  8.     Displaying text should be easier than it is.  This library
  9.     provides a group of functions which allow the basics of displaying
  10.     and editing of text in the form of a TE Record.
  11.     
  12.     Functions Include:
  13.     
  14.       FnTE_SetUpTEWindow      Creates TE Record to fill window
  15.       FnTE_MaintainCursor     Call this and TEIdle() in event loop
  16.       FnTE_UpdateWindow       Redraws window contents
  17.       FnTE_DoActivate         Activates/Deactivates window
  18.       FnTE_DoKeyDown          Handles keyboard inputs
  19.       FnTE_DoEditMenu         Handles cut and paste of TE data
  20.       FnTE_DoContent          Handles mousedown in window
  21.       FnTE_DetSBarIncr        Refreshes scroll bar parameters
  22.       FnTE_GrowWindow         Handles resizing of window
  23.       FnTE_FrameRect          Puts frame around text in window
  24.       FnTE_GetTEXT            Puts TEXT resource into TE Record
  25.       
  26.       // Semi-private
  27.       FnTE_AdjustText
  28.       FnTE_SetToCursorPos
  29.       FnTE_CheckScrollBar
  30.       FnTE_ScrollProc
  31. */
  32.  
  33. #define FnCUT        1
  34. #define FnCOPY       2
  35. #define FnPASTE      3
  36. #define FnCLEAR      4
  37. #define FnSELECT_ALL 5
  38.  
  39. #define DEL_KEY      8
  40. #define DOWN_ARROW   31
  41. #define UP_ARROW     30
  42. #define LEFT_ARROW   28
  43. #define RIGHT_ARROW  29
  44. #define PAGE_DOWN    12
  45. #define PAGE_UP      11
  46. #define HOME         1
  47. #define END          4
  48.  
  49. #define MAX_CHAR     32000
  50.  
  51. TEHandle      *tempTEHptr;
  52. ControlHandle *tempVScrollptr;
  53. Cursor        IBeamCursor;
  54. Boolean       IBeamCursorDefined = FALSE;
  55.  
  56. // Prototypes
  57.  
  58. Boolean FnTE_SetUpTEWindow  ( WindowPtr     w,
  59.                               Boolean       hasGrowIcon,
  60.                               Boolean       wordWrap,
  61.                               short         font,
  62.                               short         textSize,
  63.                               short         textInsetPixels,
  64.                               // results //
  65.                               TEHandle      *te,
  66.                               ControlHandle *vScroll );
  67. void    FnTE_MaintainCursor ( WindowPtr     w,
  68.                               TEHandle      *te );
  69. void    FnTE_UpdateWindow   ( WindowPtr     w,
  70.                               TEHandle      *te,
  71.                               Boolean       hasGrowIcon );
  72. void    FnTE_DoActivate     ( WindowPtr     w,
  73.                               TEHandle      *te,
  74.                               ControlHandle *vScroll,
  75.                               Boolean       hasGrowIcon,
  76.                               Boolean       activate );
  77. void    FnTE_DoKeyDown      ( char          theChar,
  78.                               TEHandle      *te,
  79.                               ControlHandle *vScroll,
  80.                               char          *dirty );
  81. void    FnTE_DoEditMenu     ( int           item,
  82.                               TEHandle      *te,
  83.                               ControlHandle *vScroll,
  84.                               char          *dirty,
  85.                               int           cutCommand,
  86.                               int           copyCommand,
  87.                               int           pasteCommand,
  88.                               int           clearCommand,
  89.                               int           selectAllCommand );
  90. void    FnTE_DoContent      ( WindowPtr     w, 
  91.                               EventRecord   *e,
  92.                               TEHandle      *te,
  93.                               ControlHandle *vScroll );
  94. void    FnTE_DetSBarIncr    ( TEHandle      *te,
  95.                               ControlHandle *vScroll );
  96. void    FnTE_GrowWindow     ( WindowPtr     w,
  97.                               TEHandle      *te,
  98.                               ControlHandle *vScroll,
  99.                               short         textInsetPixels,
  100.                               Point         clickLoc );
  101. void   FnTE_FrameRect       ( WindowPtr     w,
  102.                               TEHandle      *te,
  103.                               short         inset );
  104. void   FnTE_GetTEXT         ( short         rsrcID,
  105.                               TEHandle      *te,
  106.                               ControlHandle *vScroll );
  107.  
  108. void    FnTE_AdjustText     ( TEHandle *te, ControlHandle *vScroll );
  109. void    FnTE_SetToCursorPos ( TEHandle *te, ControlHandle *vScroll );
  110. void    FnTE_CheckScrollBar ( TEHandle *te, ControlHandle *vScroll );
  111. pascal void FnTE_ScrollProc ( ControlHandle theControl,
  112.                               short         theCode );
  113.  
  114. extern void FnErr_DisplayStr(   Str255 s1,
  115.                          Str255 s2,
  116.                          Str255 s3,
  117.                          Str255 s4,
  118.                          int    quitFlag );
  119.  
  120.  
  121. /********** SetUpTEWindow */
  122.  
  123. Boolean FnTE_SetUpTEWindow(
  124.     WindowPtr  w,
  125.     Boolean    hasGrowIcon,
  126.     Boolean    wordWrap,
  127.     short      font,
  128.     short      textSize,
  129.     short      textInsetPixels,
  130.     // results //
  131.     TEHandle      *te,
  132.     ControlHandle *vScroll )
  133. /*
  134.     FnSetUpWindow takes information you supply about a window
  135.     and it's default text parameters then returns a TEHandle to
  136.     a text pane that fills the window and a ControlHandle to
  137.     a scroll bar that is located at the right of the window.
  138.     Returns FALSE if error detected during routine.
  139. */
  140. {
  141.     Rect       destRect, viewRect;
  142.     Rect       vSBarRect;
  143.     GrafPtr    oldPort;
  144.     int        SBarWidth = 15;
  145.  
  146.     // define basic te stuff
  147.     GetPort( &oldPort );
  148.     SetPort( w );
  149.     TextFont( font );
  150.     TextSize( textSize ); 
  151.  
  152.     // set scroll bar rect       
  153.     vSBarRect = (*w).portRect;
  154.     vSBarRect.left = vSBarRect.right - SBarWidth;
  155.     vSBarRect.right += 1;
  156.     vSBarRect.top -= 1;
  157.     if( hasGrowIcon )
  158.         vSBarRect.bottom -= 14;
  159.     else
  160.         vSBarRect.bottom += 1;
  161.  
  162.     // create new control      
  163.     *vScroll = NewControl( w, &vSBarRect, "\p", 1, 0, 0, 0,
  164.         scrollBarProc, 0L);
  165.     if( *vScroll == NULL )
  166.         return FALSE;
  167.  
  168.     // define te view and dest rects
  169.     viewRect = w->portRect;
  170.     viewRect.right -= SBarWidth;
  171.     if( hasGrowIcon )
  172.         viewRect.bottom -= SBarWidth;
  173.     InsetRect(&viewRect, textInsetPixels, textInsetPixels);
  174.     destRect = viewRect;
  175.  
  176.     // create new te record
  177.     *te = TENew( &destRect, &viewRect );
  178.     if( *te == NULL )
  179.         return FALSE;
  180.     if( wordWrap )
  181.         (***te).crOnly = 1;
  182.     else
  183.         (***te).crOnly = -1;
  184.  
  185.     // set autoview flag for automatic scrolling
  186.     TEAutoView( TRUE, *te );
  187.  
  188.     SetPort( oldPort );
  189.     return TRUE;
  190. }
  191.  
  192.  
  193. /********** MaintainCursor */
  194.  
  195. void FnTE_MaintainCursor( WindowPtr w, TEHandle *te )
  196. /*
  197.     Maintains cursor icon in TE window.  Call this function each time
  198.     through event loop (also call Macintosh function TEIdle to blink
  199.     cursor).
  200. */
  201. {
  202.     Point       pt;
  203.     WindowPeek  wPtr;
  204.     GrafPtr     savePort;
  205.     CursHandle  hCurs;
  206.  
  207.     /*
  208.         Variables hIBeamCursor and IBeamCursorDefined must be defined
  209.         at top of this FnTELibrary.c file.
  210.     */
  211.  
  212.     if( !IBeamCursorDefined )
  213.     {
  214.         hCurs = GetCursor(1);  /* IBeam Cusor ID */
  215.         IBeamCursor = **hCurs;
  216.         IBeamCursorDefined = TRUE;
  217.     }
  218.  
  219.     wPtr = (WindowPeek)FrontWindow();
  220.     if( (WindowPtr)wPtr == w )
  221.     {
  222.         if( wPtr->windowKind >= 0 )
  223.         {
  224.             GetPort( &savePort );
  225.             SetPort( (GrafPtr)wPtr );
  226.             GetMouse( &pt );
  227.             if( PtInRect( pt, &(***te).viewRect ) )
  228.             {
  229.                 SetCursor( &IBeamCursor );
  230.             }
  231.             else
  232.             {
  233.                 SetCursor( &qd.arrow );
  234.             }
  235.             SetPort( savePort );
  236.         }
  237.     }
  238. }
  239.  
  240.  
  241. /********** UpdateWindow */
  242.  
  243. void FnTE_UpdateWindow( WindowPtr w, TEHandle *te, Boolean hasGrowIcon )
  244. /*
  245.     Updates a text window.
  246. */
  247. {
  248.     GrafPtr savePort;
  249.  
  250.     GetPort(&savePort);
  251.     SetPort(w);
  252.  
  253.     BeginUpdate(w);
  254.     EraseRect(&w->portRect);
  255.     DrawControls(w);
  256.     if( hasGrowIcon )
  257.         DrawGrowIcon(w);
  258.     TEUpdate(&w->portRect, *te);
  259.     EndUpdate(w);
  260.  
  261.     SetPort(savePort);
  262. }
  263.  
  264.  
  265. /********** DoActivate */
  266. void FnTE_DoActivate( WindowPtr     w,
  267.                       TEHandle      *te,
  268.                       ControlHandle *vScroll,
  269.                       Boolean       hasGrowIcon,
  270.                       Boolean       activate )
  271. /*
  272.     Handles activateEvt for TE window.
  273. */
  274. {
  275.     if( activate )
  276.     {
  277.         TEActivate( *te );
  278.         ShowControl( *vScroll );
  279.         if( hasGrowIcon ) DrawGrowIcon( w );
  280.         TEFromScrap();
  281.     }
  282.     else
  283.     {
  284.         TEDeactivate( *te );
  285.         HideControl( *vScroll );
  286.         if( hasGrowIcon ) DrawGrowIcon( w );
  287.         ZeroScrap();
  288.         TEToScrap();
  289.     }
  290. }
  291.  
  292.  
  293. /********** DoKeyDown */
  294.  
  295. void FnTE_DoKeyDown( char          theChar,
  296.                      TEHandle      *te,
  297.                      ControlHandle *vScroll,
  298.                      char          *dirty )
  299. /*
  300.     Handles key press in TE region.  Uses functions FnTE_SetToCursorPos
  301.     and FnTE_AdjustText to postion text and scroll bar.
  302. */
  303. {
  304.     int count = 256;          // same as used in FnIO_Library
  305.     tempTEHptr = te;          // used in Scroll_Proc
  306.     tempVScrollptr = vScroll; // used in Scroll_Proc
  307.  
  308.     if( (((***te).teLength + count) >= MAX_CHAR) &&
  309.         (theChar != DEL_KEY) )
  310.     {
  311.         FnErr_DisplayStr(   
  312.             "\pFile size limits have been exceeded.  ",
  313.             "\pPlease save your work and then try to ",
  314.             "\preduce file size.",
  315.             "\p",
  316.             FALSE );  // don't quit
  317.     }
  318.     else
  319.     {
  320.         switch( theChar )
  321.         {
  322.             case DOWN_ARROW:
  323.             case UP_ARROW:
  324.             case LEFT_ARROW:
  325.             case RIGHT_ARROW:
  326.                 TEKey( theChar, *te );
  327.                 FnTE_SetToCursorPos( te, vScroll );
  328.                 FnTE_AdjustText( te, vScroll );
  329.                 break;
  330.             case PAGE_DOWN:
  331.                 FnTE_ScrollProc( *vScroll, (short)inPageDown );
  332.                 break;
  333.             case PAGE_UP:
  334.                 FnTE_ScrollProc( *vScroll, (short)inPageUp );
  335.                 break;
  336.             case HOME:
  337.                 SetCtlValue( *vScroll, 0 );
  338.                 FnTE_AdjustText( te, vScroll );
  339.                 break;
  340.             case END:
  341.                 SetCtlValue( *vScroll, GetCtlMax(*vScroll) );
  342.                 FnTE_AdjustText( te, vScroll );
  343.                 break;
  344.             default:
  345.                 {
  346.                     TEKey( theChar, *te );
  347.                     FnTE_SetToCursorPos( te, vScroll );
  348.                     FnTE_AdjustText( te, vScroll );
  349.                     *dirty = 1;
  350.                 }
  351.         }
  352.     }
  353. }
  354.  
  355.  
  356. /********** DoEditMenu */
  357.  
  358. void FnTE_DoEditMenu( int           theItem,
  359.                       TEHandle      *te,
  360.                       ControlHandle *vScroll,
  361.                       char          *dirty,
  362.                       int           cutCommand,
  363.                       int           copyCommand,
  364.                       int           pasteCommand,
  365.                       int           clearCommand,
  366.                       int           selectAll )
  367. /*
  368.     Performs cut and paste function of standard Edit menu items.
  369. */
  370. {
  371.     if     ( theItem == cutCommand )   theItem = FnCUT;
  372.     else if( theItem == copyCommand )  theItem = FnCOPY;
  373.     else if( theItem == pasteCommand ) theItem = FnPASTE;
  374.     else if( theItem == clearCommand ) theItem = FnCLEAR;
  375.     else if( theItem == selectAll )    theItem = FnSELECT_ALL;
  376.  
  377.     switch( theItem )
  378.     {
  379.         case FnCUT:
  380.             TECut( *te );
  381.             FnTE_DetSBarIncr( te, vScroll );
  382.             FnTE_SetToCursorPos( te, vScroll );
  383.             FnTE_AdjustText( te, vScroll );
  384.             *dirty = 1;
  385.             break;
  386.         case FnCOPY:
  387.             TECopy( *te );
  388.             break;
  389.         case FnPASTE:
  390.             if(TEGetScrapLen() + (***te).teLength < MAX_CHAR)
  391.             {
  392.                 TEPaste( *te );
  393.                 FnTE_DetSBarIncr( te, vScroll );
  394.                 FnTE_SetToCursorPos( te, vScroll );
  395.                 FnTE_AdjustText( te, vScroll );
  396.                 *dirty = 1;
  397.             }
  398.             else
  399.             {
  400.                 FnErr_DisplayStr(
  401.                     "\pPaste size too large.","\p","\p","\p", FALSE);
  402.             }
  403.             break;
  404.         case FnCLEAR:
  405.             TEDelete( *te );
  406.             FnTE_DetSBarIncr( te, vScroll );
  407.             FnTE_SetToCursorPos( te, vScroll );
  408.             FnTE_AdjustText( te, vScroll );
  409.             *dirty = 1;
  410.             break;
  411.         case FnSELECT_ALL:
  412.             TESetSelect( 0, 32767, *te );
  413.             FnTE_SetToCursorPos( te, vScroll );
  414.             FnTE_AdjustText( te, vScroll );
  415.             break;
  416.     }
  417. }
  418.  
  419.  
  420. /********** DoContent */
  421.  
  422. void FnTE_DoContent( WindowPtr     w, 
  423.                      EventRecord   *e,
  424.                      TEHandle      *te,
  425.                      ControlHandle *vScroll )
  426. /*
  427.     Use this procedure when user clicks in content region of TE window.
  428.     Uses the TnTE_ScrollProc below to take care of scroll bar function.
  429.     Also uses FnTE_AdjustText function.
  430. */
  431. {
  432.     int                cntlCode;
  433.     ControlHandle      cntl;
  434.     int                pageSize;
  435.     GrafPtr            savePort;
  436.  
  437.     GetPort(&savePort);
  438.     SetPort(w);
  439.  
  440.     GlobalToLocal(&e->where);
  441.     if( (cntlCode = FindControl(e->where, w, &cntl)) == 0 )
  442.     {
  443.         if( PtInRect( e->where, &(***te).viewRect) )
  444.         {
  445.             TEClick( e->where, (e->modifiers & shiftKey) != 0, *te );
  446.             FnTE_CheckScrollBar( te, vScroll );
  447.         }
  448.     }
  449.     else if( cntlCode == inThumb )
  450.     {
  451.         TrackControl( cntl, e->where, 0L );
  452.         FnTE_AdjustText( te, vScroll );
  453.     }
  454.     else
  455.     {
  456.         tempTEHptr = te;
  457.         tempVScrollptr = vScroll;
  458.         TrackControl( cntl, e->where, FnTE_ScrollProc );
  459.     }
  460.  
  461.     SetPort(savePort);
  462. }
  463.  
  464.  
  465. /********** DetSBarIncr */
  466.  
  467. void FnTE_DetSBarIncr( TEHandle *te, ControlHandle *vScroll )
  468. /*
  469.     Determines number of scroll bar increments based on amount of
  470.     text pointed to in TEHandle te.
  471. */
  472. {
  473.     register int nIncr, nLinesDisplayed, len;
  474.  
  475.     nLinesDisplayed = ((***te).viewRect.bottom-(***te).viewRect.top) / 
  476.         (***te).lineHeight;
  477.     nIncr = (***te).nLines - nLinesDisplayed;
  478.     len = (***te).teLength;
  479.     if( len <= 1 ) len = 1;
  480.     if( (*((***te).hText))[len-1] == '\r' )
  481.       nIncr++;
  482.  
  483.     if( nIncr < 0 )
  484.         nIncr = 0;
  485.     if( nIncr != GetCtlMax( *vScroll ) )
  486.         SetCtlMax( *vScroll, nIncr );
  487. }
  488.  
  489.  
  490. /********** GrowWindow */
  491.  
  492. void FnTE_GrowWindow( WindowPtr     w,
  493.                       TEHandle      *te,
  494.                       ControlHandle *vScroll,
  495.                       short         textInsetPixels,
  496.                       Point         clickLoc )
  497. /*
  498.     Use this function to resize a TE window.
  499. */
  500. {
  501.     GrafPtr savePort;
  502.     long    theResult;
  503.     Rect    oldHorizBar;
  504.     Rect    r;
  505.     int     SBarWidth = 15;
  506.     float   percent;
  507.     float   currentValue;
  508.     float   currentMax;
  509.  
  510.     GetPort( &savePort );
  511.     SetPort( w );
  512.     // although not used, calculate size of bottom scroll bar
  513.     oldHorizBar = w->portRect;
  514.     oldHorizBar.top = oldHorizBar.bottom - (SBarWidth + 1);
  515.     currentValue = GetCtlValue( *vScroll );
  516.     currentMax = GetCtlMax( *vScroll );
  517.     if( currentMax > 0 )
  518.         percent = currentValue / currentMax;
  519.     else
  520.         percent = 0.0;
  521.     SetRect( &r, 100, 100, qd.screenBits.bounds.right,
  522.         qd.screenBits.bounds.bottom );
  523.     theResult = GrowWindow( w, clickLoc, &r );
  524.     if (theResult == 0)
  525.       return;
  526.     SizeWindow( w, LoWord(theResult), HiWord(theResult), FALSE );
  527.     InvalRect( &w->portRect );
  528.     EraseRect( &w->portRect );
  529.     
  530.     (***te).viewRect = w->portRect;
  531.     (***te).viewRect.right -= SBarWidth;
  532.     (***te).viewRect.bottom -= SBarWidth;
  533.     InsetRect( &(***te).viewRect, textInsetPixels, textInsetPixels );
  534.     (***te).destRect = (***te).viewRect;
  535.     TECalText( *te );
  536.     MoveControl( *vScroll,
  537.                  w->portRect.right - SBarWidth,
  538.                  w->portRect.top - 1 );
  539.     SizeControl( *vScroll,
  540.                  SBarWidth + 1,
  541.                  w->portRect.bottom - w->portRect.top - (SBarWidth-2) );
  542.     FnTE_DetSBarIncr( te, vScroll );
  543.     percent = percent * (float)GetCtlMax( *vScroll );
  544.     SetCtlValue( *vScroll, int( percent ) );
  545.     FnTE_AdjustText( te, vScroll );
  546.     DrawGrowIcon( w );
  547.     TEUpdate( &w->portRect, *te );
  548.     ValidRect( &w->portRect );
  549.     
  550.     SetPort( savePort );
  551. }
  552.  
  553.  
  554. /********** FrameRect */
  555.  
  556. void FnTE_FrameRect( WindowPtr w, TEHandle *te, short inset )
  557. {
  558.     Rect     itemRect;
  559.     PenState thePnState;
  560.     GrafPtr  oldPort;
  561.  
  562.     GetPort( &oldPort );
  563.     SetPort( w );
  564.     itemRect = (***te).viewRect;
  565.     InsetRect( &itemRect, -inset, -inset );
  566.     itemRect.right += 1;
  567.     GetPenState( &thePnState );
  568.     PenNormal();
  569.     FrameRect( &itemRect );
  570.     SetPenState( &thePnState );
  571.     SetPort( oldPort );
  572. }
  573.  
  574.  
  575. /********** GetTEXT */
  576.  
  577. void FnTE_GetTEXT( short rsrcID, TEHandle *te, ControlHandle *vScroll )
  578. /*
  579.     Reads in TEXT resource into TE record and resets scroll bar.  Need
  580.     to call FnTE_UpdateWindow to display text.
  581. */
  582. {
  583.     (**te)->hText = GetResource( 'TEXT', rsrcID );
  584.     TECalText( *te );
  585.     (***te).destRect.top = (***te).viewRect.top;
  586.     SetCtlValue( *vScroll, GetCtlMin( *vScroll ) );
  587.     FnTE_DetSBarIncr( te, vScroll );
  588. }
  589.  
  590.  
  591. /********** AdjustText */
  592.  
  593. void FnTE_AdjustText( TEHandle *te, ControlHandle *vScroll )
  594. /*
  595.     Takes current value of the scroll bar position and adjusts text
  596.     for specified TextEdit pane.  Call this function after user
  597.     clicks in scroll bar.
  598. */
  599. {
  600.     int  oldScroll, newScroll, delta;
  601.  
  602.     oldScroll = (***te).viewRect.top - (***te).destRect.top;
  603.     newScroll = GetCtlValue( *vScroll ) * (***te).lineHeight;
  604.     delta = oldScroll - newScroll;
  605.     if( delta != 0 )
  606.         TEScroll( 0, delta, *te );
  607. }
  608.  
  609.  
  610. /********** SetToCursorPos */
  611.  
  612. void FnTE_SetToCursorPos( TEHandle *te, ControlHandle *vScroll )
  613. /*
  614.     Use this function to adjust scroll bar position such that the
  615.     currently selected text and/or insertion cursor position is 
  616.     displayed in middle of te window.  You must make a call to a 
  617.     function like FnTE_AdjustText after calling this function to redraw
  618.     text based on new scroll bar position.
  619. */
  620. {
  621.     register int topLine,bottomLine,theLine,nIncr,nLinesDisplayed,len;
  622.  
  623.     // following could be replaced by call to FnDetSBarIncr
  624.     nLinesDisplayed = ((***te).viewRect.bottom-(***te).viewRect.top) / 
  625.         (***te).lineHeight;
  626.     nIncr = (***te).nLines - nLinesDisplayed;
  627.     
  628.     len = (***te).teLength;
  629.     if( len <= 1 ) len = 1;
  630.     if( (*((***te).hText))[len-1] == '\r' )
  631.       nIncr++;
  632.  
  633.     if( nIncr < 0 )
  634.         nIncr = 0;
  635.     SetCtlMax( *vScroll, nIncr );
  636.  
  637.     topLine = GetCtlValue( *vScroll );
  638.     bottomLine = topLine + nLinesDisplayed;
  639.     if( (***te).selStart < (***te).lineStarts[topLine] ||
  640.         (***te).selStart >= (***te).lineStarts[bottomLine] )
  641.     {
  642.         for( theLine = 0;
  643.             (***te).selStart >= (***te).lineStarts[theLine];
  644.             theLine++ )
  645.             /* count */ ;
  646.         SetCtlValue( *vScroll, theLine - nLinesDisplayed / 2 );
  647.     }
  648. }
  649.  
  650.  
  651. /********** CheckScrollBar */
  652.  
  653. void FnTE_CheckScrollBar( TEHandle *te, ControlHandle *vScroll )
  654. /*
  655.     Use this function to check (and adjust) scroll bar such that the 
  656.     current top of the TE window matches the scroll bar increment.  This
  657.     should be called when a mouseDown occurs in a TE window which has 
  658.     auto scrolling enabled.
  659. */
  660. {
  661.     register int incr;
  662.  
  663.     incr = ((***te).viewRect.top-(***te).destRect.top) /
  664.         (***te).lineHeight;
  665.     if( incr < 0 )
  666.         incr = 0;
  667.     if( incr > GetCtlMax( *vScroll ) )
  668.         incr = GetCtlMax( *vScroll );
  669.     if( incr != GetCtlValue( *vScroll ) )
  670.         SetCtlValue( *vScroll, incr );
  671. }
  672.  
  673.  
  674. /********** PASCAL ScrollProc */
  675.  
  676. pascal void FnTE_ScrollProc( ControlHandle theControl, short theCode )
  677. /*
  678.     Scroll procedure used for TE scroll bar.  Uses FnTE_AdjustText
  679.     function to update text.
  680. */
  681. {
  682.     int    pageSize;
  683.     int    scrollAmt;
  684.     int    oldCtl;
  685.  
  686.     if( theCode == 0 )
  687.         return;
  688.  
  689.     pageSize =
  690.         ((***tempTEHptr).viewRect.bottom -
  691.         (***tempTEHptr).viewRect.top) /
  692.         (***tempTEHptr).lineHeight - 1;
  693.  
  694.     switch( theCode )
  695.     {
  696.         case inUpButton: 
  697.             scrollAmt = -1;
  698.             break;
  699.         case inDownButton: 
  700.             scrollAmt = 1;
  701.             break;
  702.         case inPageUp: 
  703.             scrollAmt = -pageSize;
  704.             break;
  705.         case inPageDown: 
  706.             scrollAmt = pageSize;
  707.             break;
  708.     }
  709.  
  710.     oldCtl = GetCtlValue( theControl );
  711.     SetCtlValue( theControl, oldCtl + scrollAmt );
  712.  
  713.     FnTE_AdjustText( tempTEHptr, tempVScrollptr );
  714. }
  715.  
  716. // End of File